#应用场景：多个参数的时候
#https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&tn=monline_3_dg&wd=%E5%91%A8%E6%9D%B0%E4%BC%A6&sex=%E7%94%B7
#https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&tn=monline_3_dg&wd=周杰伦&sex=男
import urllib.request
#data = {
#    'wd':'周杰伦',
#    'sex':'男'
#}
#a = urllib.parse.urlencode(data)
#print(a)
import urllib.request
import urllib.parse
base_url ='https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&tn=monline_3_dg&'
data = {
    'wd':'周杰伦',
    'sex':'男',
    'location':'台湾'
}

new_data = urllib.parse.urlencode(data)

url = base_url + new_data
headers = {'User-Agent':
               'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0'}

#请求对象的定制
request = urllib.request.Request(url=url,headers=headers)

response = urllib.request.urlopen(request)

#获取网页源码的数据
content = response.read().decode('utf-8')
print(content)



